//package com.jcoinexchange.market.controller;
//
//import com.jcoinexchange.market.common.vo.KLineListReq;
//import com.jcoinexchange.web.entity.BasicResponse;
//import com.jcoinexchange.market.common.vo.KLineListRes;
//import com.jcoinexchange.market.business.KLineService;
//import com.jcoinexchange.web.entity.BasicResponse;
//import com.jcoinexchange.web.entity.ResponseBaseCode;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.apache.commons.lang3.RandomUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.BindingResult;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import jakarta.validation.Valid;
//import java.math.BigDecimal;
//import java.util.*;
//
//@Tag(name = "行情K线信息")
//@RestController
//@RequestMapping("/kLine")
//public class KLineController {
//
//    @Autowired
//    private KLineService kLineService;
//
//    @Operation(summary = "K线历史列表")
//    @GetMapping("/list")
//    public BasicResponse<List<KLineListRes>> list(@Valid KLineListReq req,
//                                 BindingResult bindingResult) {
//
//        if (bindingResult.hasErrors()) {
//            return BasicResponse.error(ResponseBaseCode.ERROR_PARAM_INVALID, bindingResult.getFieldError().getDefaultMessage());
//        }
//
//        List<KLineListRes> list = kLineService.list(req);
//
//        return BasicResponse.success(list);
//    }
//
//    @Operation(summary = "K线历史测试随机列表")
//    @GetMapping("/list-test")
//    public BasicResponse<List<KLineListRes>> listTest(@Valid KLineListReq req,
//                                 BindingResult bindingResult) {
//
//        if (bindingResult.hasErrors()) {
//            return BasicResponse.error(ResponseBaseCode.ERROR_PARAM_INVALID, bindingResult.getFieldError().getDefaultMessage());
//        }
//
//        List<KLineListRes> kLineListResList = new ArrayList<>();
//
//        BigDecimal close = BigDecimal.ZERO;
//        BigDecimal open;
//        long date = new Date().getTime();
//        for (int i = 0; i < 100; i++) {
//            if (close.compareTo(BigDecimal.ZERO) == 0) {
//                open = BigDecimal.valueOf(RandomUtils.nextDouble(20, 100));
//            } else {
//                open = close;
//            }
//            if (i % 2 == 0) {
//                close = open.add(BigDecimal.valueOf(RandomUtils.nextDouble(1, 5)));
//            } else {
//                close = open.subtract(BigDecimal.valueOf(RandomUtils.nextDouble(1, 5)));
//            }
//            date = date + 60;
//            KLineListRes kLineListRes = new KLineListRes();
//            kLineListRes.setTime(date);
//            kLineListRes.setOpen(open);
//            kLineListRes.setClose(close);
//            kLineListRes.setLow(close.subtract(BigDecimal.valueOf(RandomUtils.nextDouble(1, 5))));
//            kLineListRes.setHigh(close.add(BigDecimal.valueOf(RandomUtils.nextDouble(1, 5))));
//            kLineListRes.setVol(BigDecimal.valueOf(RandomUtils.nextDouble(1, 20)));
//            kLineListResList.add(kLineListRes);
//        }
//
//
//        return BasicResponse.success(kLineListResList);
//    }
//
//}
